package team.stride.tabs.home;

import team.stride.R;
import team.stride.tabs.TabGroupActivity;
import team.stride.utils.UtilsStride;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class NewTrackActivity extends Activity {
	private EditText runningName;
	// private Button trackName;
//	private TextView userName;
	private CheckBox isMusic;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_track_layout);

		// trackName = (Button) findViewById(R.id.newTrackTrackName);
		runningName = (EditText) findViewById(R.id.newTrackRunningName);
		isMusic = (CheckBox) findViewById(R.id.newTrackIsMusic);

		runningName.setText(UtilsStride.runningName);
		isMusic.setChecked(UtilsStride.isMusic);
		if (isMusic.isChecked())
			UtilsStride.playMusic();
		isMusic.setOnCheckedChangeListener(new OnCheckedChangeListener()
		{
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
			{
				if (isChecked)
				{
					// cauta playlist
					UtilsStride.playMusic();
				}
				else
				{
					UtilsStride.stopMusic();
				}
			}
		});
		

		// trackName.setOnClickListener(new OnClickListener() {
		// @Override
		// public void onClick(final View v) {
		//
		// AlertDialog alertDialog = new
		// AlertDialog.Builder(UtilsStride.mainActivity)
		// .create();
		// alertDialog.setContentView(R.layout.track_names_layout);
		// alertDialog.setTitle("Alert 1");
		// alertDialog.setMessage("This is an alert");
		//
		// ListView listLV = (ListView) findViewById(R.id.tracksListView);
		// ArrayList<TrackListViewItem> tracksList = new
		// ArrayList<TrackListViewItem>();
		// TrackListViewItemAdapter adapter = new TrackListViewItemAdapter(
		// v.getContext(), tracksList);
		// listLV.setAdapter(adapter);
		// }
		// });

		final Button nextBtn = (Button) findViewById(R.id.next_btn);
		OnClickListener nextBtnListener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				// elena
				// UtilsStride.trackName =
				// trackName.getSelectedItem().toString();
				UtilsStride.runningName = runningName.getText().toString();
				UtilsStride.isMusic = isMusic.isChecked();

				// ionut
				// sAux = "" + trackName.getText();
				// UtilsStride.currentFileName = sAux;
				// UtilsStride.newTrack = true;
				TabGroupActivity parentActivity = (TabGroupActivity) getParent();
				Intent intent = new Intent(parentActivity,
						ChooseExerciseActivity.class);
				parentActivity.startChildActivity("ChooseExerciseActivity",
						intent);

			}
		};

		nextBtn.setOnClickListener(nextBtnListener);
	}
}
